import {BasicColumn, FormSchema} from '/@/components/Table';
import {listAccessKey} from '/@/views/system/accessKey/accessKey.api';
import {render} from '/@/utils/common/renderUtils';
import {useUserStore} from '/@/store/modules/user';

const userStore = useUserStore()

export const columns: BasicColumn[] = [
  {
    title: '应用AppId',
    width: 100,
    dataIndex: 'id',
    customRender: ({text}) => {
      return text
    }
  },
  {
    title: '应用名称',
    width: 100,
    dataIndex: 'appName',
  },
  {
    title: '商户号',
    width: 100,
    dataIndex: 'mchNo',
  },
  {
    dataIndex: 'status', 
    title: '状态',
    width: 60,
    customRender: ({text}) => {
      let color = "green"
      if (text == '0') color = 'red'
      if (text == '1') color = 'green'
      
      return render.renderTag(render.renderDict(text, 'mch_status'), color)
    },
  },
  {
    title: '创建时间',
    width: 150,
    dataIndex: 'createdAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'id',
    label: '应用AppId',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'appName',
    label: '应用名称',
    component: 'Input',
    colProps: {span: 6},
  },
  
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'mch_status',
      placeholder:'请选择状态'
    }
  },
];


export const formDetailSchema = [
  {
    field: 'id',
    label: '应用AppId',
    with: 400,
  },
  {
    field: 'appName',
    label: '应用名称'
  },
  {
    field: 'mchNo',
    label: '商户号'
  },
  {
    field: 'status', 
    label: '状态',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = 'red'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'mch_status'), color)
    },
  },
  {
    field: 'accessKeyName',
    label: '访问密钥',
    render: (curVal, data) =>  {
      if (curVal) {
        return render.renderTag(curVal, 'green')
      }
      return render.renderTag('密钥不存在', 'red')
    },
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'remark',
    label: '备注',
    labelMinWidth: 60
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '应用AppId',
    required: true,
    component: 'Input',
    ifShow: ({values}) => {
      return values.id;;
    },
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
  },
  {
    field: 'mchNo',
    label: '商户号',
    required: true,
    component: 'Input',
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
  },
  
  {
    field: 'appName',
    label: '应用名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'status',
    label: '状态',
    component: 'JDictSelectTag',
    defaultValue: "1",
    componentProps: {
      dictCode:'mch_status',
      type:'radio'
    }
  },
  {
    field: 'accessKeyId',
    label: '访问密钥',
    component: 'ApiSelect',
    componentProps: {
      api: listAccessKey,
      labelField: 'name',
      valueField: 'id',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        minRows: 3,
        maxRows: 8
      }
    },
    colProps: {
      style: 'color: red',
      sm: 24, // ≥576px
    }
  },
  
]
